<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="./bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="./css/base.css">
    <style>
        .crumbs {
            font-size: 14px;
            color: #ccc;
        }
    </style>
</head>

<body>
    <div class="container">
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                        data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#" style="display:flex;">
                        汪玮的博客
                    </a>
                </div>

                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

                    <ul class="nav navbar-nav navbar-right">
						<li><a href="/">首页</a></li>
						<li class="dropdown">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
								aria-haspopup="true" aria-expanded="false">分类 <span class="caret"></span></a>
							<ul class="dropdown-menu" id="cates">

							</ul>
						</li>
						<li><a href="/tags.html">标签</a></li>
						<li><a href="/about.html">关于我</a></li>
					</ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
        </nav>
        <div style="text-align:center;" id="info">
            

            <p class="intro">
                为了更好的理解和学习 Java 和 Hotspot 虚拟机，
                于是在 OSX Mojave 编译 & 源码调试 openJdk 8，
                中间遇到了很多问题，记录分享一下。
            </p>
        </div>
        <div class="content">
            <div style="text-align: center;">
                <img id="img" src="http://placehold.it/170x100/ff3333/ffffff?text=like%20you" alt="">
            </div>
            <div id="content"></div>
        </div>
        <hr>
        <div class="footer" style="text-align:center;font-size: 14px; color: #999;margin:10px 0;">
            首页 | 主站 | GitHub | Powered by hexo | Theme xoxo
        </div>
    </div>
</body>

<script src="./js/jquery.js"></script>
<script src="./bootstrap/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/layui/2.6.8/layui.js"></script>

<script src="https://momentjs.bootcss.com/downloads/moment.min.js"></script>
<!-- 处理时间 -->
<script>
    let url = location.href;
    let reg = /\id=(.+)\&?/;    
    let [,id] = Array.from(url.match(reg))

    if( isNaN (parseInt(id) )){
        console.log(parseInt(id))
        layer.msg('错误 ')
        // location.href= '/'
    }else{
         
    }
    function loadArticle(id) {

        $.get('http://127.0.0.1:4790/api/detail', {id}, res => {
            // console.log(res);
            if (JSON.stringify(res) === '{}') {
                location.href = '/'
                return;
            }
            let{audit_status,Update_time,author,content,id,img,name,title } =res
            // console.log('渲染成功')
             Update_time = moment(Update_time).format('YYYY- MM-DD ');
            let htmlS= `
            <h4 class="crumbs" style="text-align:left;">当前位置：首页 /  分类：${name}  </h4>
            <h3>${title}</h3>
            <div style="font-size: 14px; color: #999;">发布时间： ${Update_time} /
                分类：${name} /作者：${author}/ 点赞：888 <span class="label label-default">HTML</span> <span class="label label-default"></span>
            </div>`
            $("#info").html(htmlS )
           $("#content").html(content)
            //图片 
            if(img){
                $("#img").attr('src','http://127.0.0.1:4790/' + img)
            }else{
                    //设置默认图片
                    
            }
           
            
        }, 'json')
    }

    	//渲染分类数据 
	function renderCate(cates) {
		let cata = '';
		cates.forEach((cat) => {
			let {id,name} = cat;
            cata += `<li><a herf='/cate.html?id=${id}'>${name}</a></li>`});
		return cata;
	}


    //获取分页
    function loadPaging() {
		return $.ajax({
			url: 'http://127.0.0.1:4790/api/cate',
		})
	}


    loadArticle(id)
     
    //获取本地储存数据
     let cates = JSON.parse(localStorage.getItem("cates") || '[]');
     if(cates.length){
         let lis = renderCate(cates)
         $("cates").html(lis)
     }else{
        loadPaging().then(res=>{
            let lis = renderCate(res)
            $("#cates").html(lis)
        })
     }
</script>

</html>